package edu.nuist.javaProjct.view;

import edu.nuist.javaProjct.dao.StudentDatasourceDao;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddDataModel {
    public JPanel addDataModel;
    private JTextField uuidField;
    private JTextField nameField;

    private JButton addBtn;

    private final StudentDatasourceDao studentBasicDao=new StudentDatasourceDao();

    public AddDataModel() {
        addBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String studentUUID = uuidField.getText();
                if (studentUUID.equals("")){
                    JOptionPane.showMessageDialog(addDataModel, "请输入正确的学生信息", "请注意",JOptionPane.WARNING_MESSAGE);
                    return ;
                }
                String studentName = nameField.getText();
                if (studentName.equals("")){
                    JOptionPane.showMessageDialog(addDataModel, "请输入正确的学生信息", "请注意",JOptionPane.WARNING_MESSAGE);
                    return ;
                }


                int result=studentBasicDao.addData(studentUUID,studentName);
                if (result==1){
                    JOptionPane.showMessageDialog(addDataModel, "数据插入成功", "成功",JOptionPane.PLAIN_MESSAGE);
                }
            }
        });
    }
}
